﻿using System;
using System.Web;
using Manager;
using Model;
using System.Data;
using System.Collections.Generic;
namespace HealthSystem
{
    public class SelfItem
    {
        public string Name { get; set; }
        public string Value { get; set; }
    }
    public class SeflItemHandler : IHttpHandler
    {
        /// <summary>
        /// You will need to configure this handler in the web.config file of your 
        /// web and register it with IIS before being able to use it. For more information
        /// see the following link: http://go.microsoft.com/?linkid=8101007
        /// </summary>
        #region IHttpHandler Members

        public bool IsReusable
        {
            // Return false in case your Managed Handler cannot be reused for another request.
            // Usually this would be false in case you have some state information preserved per request.
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            //write your handler implementation here.
            if (context.Request["action"] == "selfitem")
            {
                string tjnd = context.Request["tjnd"] as string;
                string studentid = context.Request["studentid"] as string;
                ResultManager manager = new ResultManager();
                var selfresult = manager.GetSelfResult(tjnd, studentid);
                if (selfresult.Rows.Count > 0)
                {
                    List<SelfItem> list = new List<SelfItem>();
                    SelfItem item = null;
                    Dictionary<string, string> result = new Dictionary<string, string>();
                    for (int i = 0; i < 20; i++)
                    {
                        if (i % 2 == 0)
                        {
                            if (!(selfresult.Rows[0][i] is DBNull))
                            {
                                item.Name = selfresult.Rows[0][i] as string;
                                item.Value = selfresult.Rows[0][i + 1] as string;
                                list.Add(item);
                            }
                        }
                    }
                }
            }
        }

        #endregion
    }
}
